import config from '@/config'

// 增大zoom
export const zoom2Big = () => {
    const maxZoom = config.mapInitOptions.maxZoom ?? 18
    if (window.glMap.getZoom() <= maxZoom) {
        window.glMap.zoomTo(window.glMap.getZoom() + 1)
    }
}

// 缩小zoom
export const zoom2Small = () => {
    const minZoom = config.mapInitOptions.minZoom ?? 4
    if (window.glMap.getZoom() >= minZoom) {
        window.glMap.zoomTo(window.glMap.getZoom() - 1)
    }
}

// 重置地图配置
export const resetMapView = () => {
    window.glMap.flyTo(config.mapInitOptions)
}

// 切换2d/3d
export const switch23D = (type: '2d' | '3d') => {
    window.glMap.flyTo({
        pitch: type === '2d' ? 0 : 45,
        zoom: window.glMap.getZoom(),
        speed: 0.2,
        curve: 1,
    })
}

// 隐藏图层
export const hideLayer = (layerId: string) => {
    if (window.glMap.getLayer(layerId)) {
        window.glMap.setLayoutProperty(layerId, 'visibility', 'none')
    }
}

// 隐藏图层 - 数组
export const hideLayers = (layerIds: string[]) => {
    layerIds.forEach(id => {
        hideLayer(id)
    })
}

// 展示图层
export const showLayer = (layerId: string) => {
    if (window.glMap.getLayer(layerId)) {
        window.glMap.setLayoutProperty(layerId, 'visibility', 'visible')
    }
}

// 展示图层 - 数组
export const showLayers = (layerIds: string[]) => {
    layerIds.forEach(id => {
        showLayer(id)
    })
}
